﻿using Gj;
using UnityEngine;

public class PopupSize : NodeSize
{
    public PopupHelper popup;
    public float width;
    public float height;
    public float offset;
    public RectTransform rectTransform;
    public float safeOffset;

    protected override void OnRefresh(float rw, float rh, float w, float h, float s)
    {
        var cw = w / s;
        var ch = h / s;

        popup.RefreshWidthHeight((width > 0 ? cw > width ? width : cw : cw) - offset,
            (height > 0 ? ch > height ? height : ch : ch) - offset);
        
        if (Game.GetDevicePlatform() != "Mobile") return;
        if (SystemInput.screenOrientation == ScreenOrientation.LandscapeLeft)
        {
            rectTransform.offsetMin = new Vector2(safeOffset, 0);
            rectTransform.offsetMax = new Vector2(0, 0);
        }

        if (SystemInput.screenOrientation == ScreenOrientation.LandscapeRight)
        {
            rectTransform.offsetMin = new Vector2(0, 0);
            rectTransform.offsetMax = new Vector2(safeOffset * -1, 0);
        }
    }
}